package com.yh.base.interceptor;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;

import com.yh.base.common.Constant;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class ActionInterceptor extends AbstractInterceptor implements ServletRequestAware {

    private static final long serialVersionUID = -2382538492438678333L;

    HttpServletRequest request;

    @Override
    public String intercept(ActionInvocation invocation) throws Exception {
        // 获取调用的方法
        String invokeMethodName = invocation.getProxy().getMethod();
        // 设置方法名到ValueStack
        invocation.getStack().set(Constant.CON_PAGE_RESULT_VALUE_KEY, invokeMethodName);

        String result = invocation.invoke();

//        // action 执行后方法
//        String sql = ObjectUtil.toString(request.getAttribute(Constant.CON_REQUEST_RUNTIME_SQL_KEY));
//        invocation.getStack().set(Constant.CON_REQUEST_RUNTIME_SQL_KEY, sql);

        return result;
    }

    public void setServletRequest(HttpServletRequest req) {
        this.request = req;
    }
}
